import time

import requests
from config.config import *

def send_feishu_message():
    if FEISHU_IS_SEND:

        #构造富文本消息
        # "tag":"text"表示文本内容
        #"tag": "a"表示的是超链接
        #"href":"https://www.baidu.com"表示超链接的跳转地址
        message_data = [
            [
                {
                    "tag":"text",
                    "text":f"项目名称:{PROJECT}"
                }
            ],
            [
                {
                    "tag":"text",
                    "text":f"执行时间:{time.strftime('%Y-%m-%d %H:%M:%S')}"
                }
            ],
            [
                {
                    "tag": "text",
                    "text": "详细信息:"
                },
                {
                    "tag": "a",
                    "text":"查看测试报告",
                    "href":"https://www.baidu.com"
                }
            ]
        ]

        #构建最终的消息体
        payload = {
            "msg_type": "post",
            "content": {
                "post":{
                    "zh_cn":{
                        "title":"接口自动化测试报告",
                        "content":message_data
                    }
                }
            }
        }

        #发送请求
        response = requests.post(WEBHOOK, json=payload)
        return response





